package com.rongxun.hbwallet.ui.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.rongxun.hbwallet.R;
import com.rongxun.utils.wallet.VerifyMnemonicWordTag;

import java.util.List;


/**
 * Created by dwq on 2018/3/13/013.
 * e-mail:lomapa@163.com
 */

public class ExcavateAdapter extends BaseQuickAdapter<VerifyMnemonicWordTag, BaseViewHolder> {

    public ExcavateAdapter(int layoutResId, @Nullable List<VerifyMnemonicWordTag> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VerifyMnemonicWordTag verifyMnemonicWordTag) {
        if (verifyMnemonicWordTag.isSelected()) {
            helper.setBackgroundRes(R.id.tv_mnemonic_word, R.drawable.mnemonic_item_tag_bg_select_shape);
            helper.setTextColor(R.id.tv_mnemonic_word, mContext.getResources().getColor(R.color.white));
        } else {
            helper.setBackgroundRes(R.id.tv_mnemonic_word, R.drawable.mnemonic_item_tag_bg_shape);
            helper.setTextColor(R.id.tv_mnemonic_word, mContext.getResources().getColor(R.color.black));
        }
        helper.setText(R.id.tv_mnemonic_word, verifyMnemonicWordTag.getMnemonicWord());
        helper.addOnClickListener(R.id.tv_mnemonic_word);
    }

    public boolean setSelection(int position) {

        VerifyMnemonicWordTag verifyMnemonicWordTag = getData().get(position);
        if (verifyMnemonicWordTag.isSelected()) {
            return false;
        }
        verifyMnemonicWordTag.setSelected(true);
       // Collections.shuffle(getData());
        notifyDataSetChanged();
        return true;
    }

    public boolean setUnselected(int position) {

        VerifyMnemonicWordTag verifyMnemonicWordTag = getData().get(position);
        if (!verifyMnemonicWordTag.isSelected()) {
            return false;
        }
        verifyMnemonicWordTag.setSelected(false);
//        Collections.shuffle(getData());
        notifyDataSetChanged();
        return true;
    }

}
